﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox1.Text))
            {
                MessageBox.Show("请输入一个数值！", "输入错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (double.TryParse(textBox1.Text, out double n))
            {
                int result;

                if (n < 0)
                {
                    result = -1;
                }
                else if (n == 0)
                {
                    result = 0;
                }
                else
                {
                    result = 1;
                }

                textBox2.Text = result.ToString();
            }
            else
            {
                MessageBox.Show("请输入有效的数值！", "输入错误",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBox1.Focus();
                textBox1.SelectAll();
            }
        }
    }
}